$(document).ready(function()
{
	//
	// Search Field Functions
	//
	var popBox = $('#searchToggle').siblings('div.suggestBox');
	var items = popBox.children('div');
	
	$('#searchToggle').click(function(e)
	{
		popBox.css('display') == 'none' ? popBox.fadeIn() : popBox.fadeOut();
		e.cancelBubble = true;
		if(e.stopPropagation) e.stopPropagation();
	});
	
	$('body').click(function(e)
	{
		popBox.hide();
	});
	
	$('#searchField').focus(function()
	{
		// dont' overwrite user input
		if(popBox.children('div:contains('+$('#searchField').val()+')').length != 0)
		{
			$('#searchField').val('');
		}
		$('#searchField').css('color', '');
	});
	
	$('#searchField').blur(function()
	{
		if($('#searchField').val() == '')
		{
			$('#searchField').val($('#searchToggle').siblings('div').children('div[sel=true]').text());
			$('#searchField').css('color', 'gray');
		}
	});
	
	items.click(function()
	{
		var elem = $(this);
		popBox.hide();
		
		// dont' overwrite user input
		if(popBox.children('div:contains('+$('#searchField').val()+')').length != 0)
		{
			$('#searchField').val(elem.text());
		}
		$('#searchArea').val(elem.attr('val'));

		items.css('font-weight', 'normal');
		items.attr('sel', 'false');
		
		elem.css('font-weight', 'bold');
		elem.attr('sel', 'true');
	});

});